package com.huitone.smspfm.interfacz.model;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.interfacz.dao.entity.SmsSendRecord;

public class RedUserRecord {
	
	public static final SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	public static final ArrayList<String> RED_USER_RESP = new ArrayList<String>(){

		private static final long serialVersionUID = 1L;

		{
			add(0,"<serialno>?</serialno>");
			add(1,"<clientname>?</clientname>");
			add(2,"<sendport>?</sendport>");
			add(3,"<mobileno>?</mobileno>");
			add(4,"<sendtime>?</sendtime>");
			add(5,"<retcode>?</retcode>");
			add(6,"<retno>?</retno>");
			add(7,"<endl/>");
		}
	};
	
	private SmsSendRecord smsRecord;
	
	public RedUserRecord(SmsSendRecord record){
		this.smsRecord = record;
	}
	
	public String toFileString(){
		StringBuffer sb = new StringBuffer();
		if(smsRecord != null){
		sb.append(ch(RED_USER_RESP.get(0),"?",smsRecord.getSmSeq()))
			.append(ch(RED_USER_RESP.get(1),"?",smsRecord.getSvrNode()))
			.append(ch(RED_USER_RESP.get(2),"?",smsRecord.getSendport()))
			.append(ch(RED_USER_RESP.get(3),"?",smsRecord.getUserNo()))
			.append(ch(RED_USER_RESP.get(4),"?",smsRecord.getSendTime() != null ? dataFormat.format(smsRecord.getSendTime()) :  ""))
			.append(ch(RED_USER_RESP.get(5),"?",smsRecord.getSendCode()))
			.append(ch(RED_USER_RESP.get(6),"?","0"))
			.append(RED_USER_RESP.get(7));
		}

		return sb.toString();
	}

	private String ch(String source,String regx,String dest){
		return StringUtils.replace(source,regx,!StringUtils.isEmpty(dest) ? dest :"");
	}
	
	
}
